package io.renren.modules.project.service.impl;

import io.renren.common.utils.RandomId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.modules.project.dao.ProjectScaleDao;
import io.renren.modules.project.entity.ProjectScaleEntity;
import io.renren.modules.project.service.ProjectScaleService;


@Service("projectScaleService")
public class ProjectScaleServiceImpl implements ProjectScaleService {
    @Autowired
    private ProjectScaleDao projectScaleDao;

    @Override
    public ProjectScaleEntity queryObject(String id) {
        ProjectScaleEntity projectScaleEntity = projectScaleDao.queryObject(id);
        if (null == projectScaleEntity){
            ProjectScaleEntity projectScaleEntitys = new ProjectScaleEntity();
            projectScaleEntitys.setManagementConstructionAmount("0.00");
            projectScaleEntitys.setTenderingAmount("0.00");
            projectScaleEntitys.setEngineeringSupervisionAmount("0.00");
            projectScaleEntitys.setSurveyDesignAmount("0.00");
            projectScaleEntitys.setOtherAmount("0.00");
            projectScaleEntitys.setFirstPartyAmount("0.00");
            projectScaleEntitys.setThreeProofingAmount("0.00");
            projectScaleEntitys.setCivilConstructionAmount("0.00");
            projectScaleEntitys.setElectricalConstructionAmount("0.00");
            projectScaleEntitys.setPrepareAmount("0.00");
            return projectScaleEntitys;
        }
        return projectScaleEntity;
    }

    @Override
    public List<ProjectScaleEntity> queryList(Map<String, Object> map) {
        return projectScaleDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return projectScaleDao.queryTotal(map);
    }

    @Override
    public void save(ProjectScaleEntity projectScale) {
        projectScaleDao.save(projectScale);
    }

    @Override
    public void update(ProjectScaleEntity projectScale) {
        projectScaleDao.update(projectScale);
    }

    @Override
    public void delete(String id) {
        projectScaleDao.delete(id);
    }

    @Override
    public void deleteBatch(String[] ids) {
        projectScaleDao.deleteBatch(ids);
    }

    @Override
    public void updateOrSave(ProjectScaleEntity projectScaleEntity) {
        if (projectScaleEntity != null) {
            if ("".equals(projectScaleEntity.getId()) || projectScaleEntity.getId() == null) {
                //如果ID为空则创建
                projectScaleEntity.setId(RandomId.createId()+"");
                Date date = new Date();
                //设置要获取到什么样的时间
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                //获取String类型的时间
                String createdate = sdf.format(date);
                projectScaleEntity.setCreationTime(createdate);
                projectScaleDao.save(projectScaleEntity);
            } else {
                //如果ID不为空则修改
                projectScaleDao.update(projectScaleEntity);
            }
        }
    }

}
